import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'stockIndexM',
  state: {},
  effects: {
    //查询合约信息
    *queryFuturesInfo({ payload, callback }, { call, put }) {
      const res = yield call(api.stockIndexFutures.queryFuturesInfo, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback();
        message.error(res ? res.msg || '查询期货合约信息失败' : '查询期货合约信息失败');
      }
    },
    //查询行情信息
    *queryMarketInfo({ payload, callback }, { call, put }) {
      const res = yield call(api.stockIndexFutures.queryMarketInfo, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback();
        message.error(res ? res.msg || '查询行情信息失败' : '查询行情信息失败');
      }
    },
    //簿记下达
    *tradeBookSave({ payload, callback }, { call, put }) {
      const response = yield call(api.stockIndexFutures.tradeBookSave, payload);
      if (response && response.code == 0) {
        callback('success');
        message.success('簿记下达成功');
      } else {
        callback();
        message.error(response ? response.msg || response?.message || '簿记下达失败' : '簿记下达失败');
      }
    },

    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
